//package xin.cymall.aop;
//
//import java.lang.reflect.Method;
//
//import org.apache.log4j.Logger;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.After;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import xin.cymall.annotation.DynamicSwitchDataSource;
//import xin.cymall.dynamic.HandlerDataSource;
//
//@Component
//@Aspect
//@Order(1)
//public class DataSourceAop {
//	
//	private static final Logger log = Logger.getLogger(DataSourceAop.class);
//	@Pointcut("@annotation(xin.cymall.annotation.DynamicSwitchDataSource)")
//	public void dataSourcePointCut() {
//
//	}
//
//	@Before("dataSourcePointCut()")
//	public void switchDataSource(JoinPoint joinPoint) throws Throwable {
//		 Method method = ((MethodSignature)joinPoint.getSignature()).getMethod();
//	        DynamicSwitchDataSource annotationClass = method.getAnnotation(DynamicSwitchDataSource.class);//获取方法上的注解
//	        if(annotationClass == null){
//	            annotationClass = joinPoint.getTarget().getClass().getAnnotation(DynamicSwitchDataSource.class);//获取类上面的注解
//	            if(annotationClass == null) return;
//	        }
//	        //获取注解上的数据源的值的信息
//	        String dataSourceKey = annotationClass.dataSource();
//	        if(dataSourceKey !=null){
//	            //给当前的执行SQL的操作设置特殊的数据源的信息
//	            HandlerDataSource.putDataSource(dataSourceKey);
//	        }
//	        log.info("AOP动态切换数据源，className"+joinPoint.getTarget().getClass().getName()+"methodName"+method.getName()+";dataSourceKey:"+dataSourceKey==""?"默认数据源":dataSourceKey);
//	}
//	@After("dataSourcePointCut()")
//	public void testAfter(JoinPoint point){
//		//清理掉当前设置的数据源，让默认的数据源不受影响
//        HandlerDataSource.clear();
//
//    }
//}
